<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    li{
      line-height: 50px;
      width:600px;
      margin-top:10px;
      background-color: purple;
    }
  </style>
</head>
<body>
  <div id="app">
    <button @click="addLi">增加一个li</button>
    <ul>
      <li v-for="(el,index) in arr">
        {{el}}
      </li>
    </ul>
  </div>
  <script src="./vue.js"></script>
  <script>
    const vm = new Vue({
      el: '#app',
      data: {
        arr: [1,2,3,4]
      },
      methods: {
        addLi () {
          this.arr.push(this.arr.length+1)
          this.$nextTick(()=>{
            //console.log('这是一个监听者，回调函数会在数据改变后，dom更新完毕后执行')
            // 获取 所有的li
            const oul = document.querySelector('ul');
            console.log(oul.children)
            oul.lastElementChild.style.background="red"
          })
          
        }
      }
    })
  </script>
</body>
</html>